<?php
/*
 * Converts min and max unix timestamps
 * to human readable dates
 */
function prepareMinMaxTimes($times){
	
	$newTimes = array();
	
	foreach($times as $row => $key){
		$key = explode(".", $key);
		array_push($newTimes, date("m-d-y G:i:s", $key[0]));
	}
	
	return $newTimes;
}

/*
 * Calculates the arrival rate
 */
function calculate_arrival_rate($requests, $startTime, $endTime){
	
	//If there are no requests in the given time interval, return 0
	if($requests == 0){
		return 0;
	}
	
	$arrivalRate = round($requests/($endTime - $startTime), 8);
	return $arrivalRate;
	
}
/*
 * Calculates the accessibility
 */
function calculate_accessibility($completeRequests, $incompleteRequests){
	//Avoid division by zero
	if($completeRequests == 0){
		return 0;
	}
	
	return round((($completeRequests-$incompleteRequests)/$completeRequests), 8)*10000/100;

}
/*
 * Calculates the accessibility
 */
function calculate_throughput($completeRequests, $startTime, $endTime){
	//Avoid division by zero
	if($completeRequests == 0){
		return 0;
	} else {
		return calculate_arrival_rate($completeRequests, $startTime, $endTime);
	}

}
//EOF general_helper.php